#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int mp[N];
int arr[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		memset(arr, 0, sizeof(arr));
		memset(mp, 0, sizeof(mp));
		int x;
		for (int i = 1; i <= n; i++) {
			cin >> arr[i];
		}
		int ans = 0;
		for (int i = n; i >= 1; i--) {
			//cout << "mp----" << mp[arr[i]] << endl;
			if (mp[arr[i]]) {
				ans = i;
				break;
			}
			else mp[arr[i]] = 1;
		}
		cout << ans << endl;
	}
	return 0;
}